{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import time\n",
    "from PIL import Image\n",
    "from PIL import ImageDraw\n",
    "plt.style.use({'figure.figsize':(10, 10)})\n",
    "pd.set_option('max_rows', 300)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Q-Table One"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Q-table One is used to void the obstacles automatically.\n",
    "### Columns:Nearest|Near|Medium|Far\n",
    "##### Columns register the states\n",
    "### Rows:Up|Down|Turn_left_45 degree|Turn_right_45_degree\n",
    "##### Rows register the actions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "Epsilon_start=1\n",
    "Epsilon_final=0.01\n",
    "Decay_rate=0.000001#he dacaying rate of the Epsilon, the range of the epsilon is 0.01-1, initially it is 1.\n",
    "Action_times=0 #Rigister the totality of the times of selecting actions, including the random selections and selection based on Q_Table\n",
    "Velocity_tripod=0.289*40\n",
    "Up_degree=np.array([-40,-20,0,20,40])\n",
    "Left_degree=np.array([-60,-80,-100,-120])\n",
    "Right_degree=np.array([60,80,100,120])\n",
    "Robot_radium=40\n",
    "Beta=0.9\n",
    "Alpha=0.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Nearest(<50cm)||Near(50cm-130cm)||Medium(130cm-210cm)|Far(>210cm)\n",
    "#Safe distance=1cm\n",
    "Q_table1_states=np.array(['L0R0U0','L0R0U1','L0R0U2','L0R0U3',\n",
    "                'L0R1U0','L0R1U1','L0R1U2','L0R1U3',\n",
    "                'L0R2U0','L0R2U1','L0R2U2','L0R2U3',\n",
    "                'L0R3U0','L0R3U1','L0R3U2','L0R3U3',\n",
    "                'L1R0U0','L1R0U1','L1R0U2','L1R0U3',\n",
    "                'L1R1U0','L1R1U1','L1R1U2','L1R1U3',\n",
    "                'L1R2U0','L1R2U1','L1R2U2','L1R2U3',\n",
    "                'L1R3U0','L1R3U1','L1R3U2','L1R3U3',\n",
    "                'L2R0U0','L2R0U1','L2R0U2','L2R0U3',\n",
    "                'L2R1U0','L2R1U1','L2R1U2','L2R1U3',\n",
    "                'L2R2U0','L2R2U1','L2R2U2','L2R2U3',\n",
    "                'L2R3U0','L2R3U1','L2R3U2','L2R3U3',\n",
    "                'L3R0U0','L3R0U1','L3R0U2','L3R0U3',\n",
    "                'L3R1U0','L3R1U1','L3R1U2','L3R1U3',\n",
    "                'L3R2U0','L3R2U1','L3R2U2','L3R2U3',\n",
    "                'L3R3U0','L3R3U1','L3R3U2','L3R3U3'])\n",
    "Q_table1_actions=np.array(['Up','Down','Left_45D','Right_45D'])\n",
    "Q_table1_actions_length=len(Q_table1_actions)\n",
    "Q_table1_states_length=len(Q_table1_states)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Up</th>\n",
       "      <th>Down</th>\n",
       "      <th>Left_45D</th>\n",
       "      <th>Right_45D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>L0R0U0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L0R0U1</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L0R0U2</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L0R0U3</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L0R1U0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Up  Down  Left_45D  Right_45D\n",
       "L0R0U0  0.0   0.0       0.0        0.0\n",
       "L0R0U1  0.0   0.0       0.0        0.0\n",
       "L0R0U2  0.0   0.0       0.0        0.0\n",
       "L0R0U3  0.0   0.0       0.0        0.0\n",
       "L0R1U0  0.0   0.0       0.0        0.0"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Q_table_real=np.zeros((Q_table1_states_length,Q_table1_actions_length))\n",
    "Q_table_real=pd.DataFrame(Q_table_real,columns=Q_table1_actions,index=Q_table1_states)\n",
    "Q_table_real.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Initial_Q_Table(LengthOfActions,LengthOfStates):\n",
    "    Q_Table=np.zeros((LengthOfStates,LengthOfActions))\n",
    "    print('***********************************************************')\n",
    "    print(\"Succeed to initialize Q-Table!\")\n",
    "    print('***********************************************************')\n",
    "    return Q_Table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Draw_map1():\n",
    "    im = Image.new(\"RGB\", size=(2000,2000),color=(0,0,0)) \n",
    "    draw = ImageDraw.Draw(im,mode='RGB') \n",
    "    draw.rectangle((40,40,1960,1960),(255,255,255),(255,255,255)) \n",
    "    draw.rectangle((1500,1000,1650,1150),(0,0,0), (0,0,0)) \n",
    "    draw.ellipse((400,700,550,850),(0,0,0), (0,0,0)) \n",
    "    draw.rectangle((200,300,350,450),(0,0,0), (0,0,0)) \n",
    "    draw.ellipse((1500,500,1550,650),(0,0,0), (0,0,0)) \n",
    "    draw.ellipse((1200,1400,1350,1550),(0,0,0), (0,0,0)) \n",
    "    draw.rectangle((700,1200,850,1350),(0,0,0), (0,0,0)) \n",
    "    draw.ellipse((300,1600,450,1750),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((100,1100,250,1250),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((1100,250,1250,400),(0,0,0),(0,0,0)) \n",
    "    draw.polygon((900, 1070,1120, 1000,1150, 1100, 1100,1090,1050, 1200),(0,0,0),(0,0,0))\n",
    "    draw.pieslice((750, 1700, 900, 1850), 0,180,(0,0,0),(0,0,0))\n",
    "    draw.ellipse((900,550,1050,700),(0,0,0),(0,0,0))\n",
    "    draw.ellipse((650,100,750,200),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((1700,130,1800,230),(0,0,0),(0,0,0))\n",
    "    draw.polygon((150, 180, 200, 180, 250, 120, 230, 90, 130, 100),(0,0,0),(0,0,0))\n",
    "#     draw.ellipse((1500-20,300-20,1500+20,300+20), (255,0,0), (255,0,0))\n",
    "    return im\n",
    "# im_show=Draw_map1()\n",
    "# plt.imshow(im_show)\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Draw_map2():\n",
    "    im = Image.new(\"RGB\", size=(2000,2000),color=(0,0,0)) \n",
    "    draw = ImageDraw.Draw(im,mode='RGB') \n",
    "    draw.rectangle((40,40,1960,1960),(255,255,255),(255,255,255))  \n",
    "    draw.rectangle((1500,1000,1600,1100),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((400,700,600,900),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((200,300,500,600),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((1500,500,1800,800),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((1200,1400,1600,1800),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((700,1200,960,1460),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((300,1600,500,1800),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((100,1100,300,1300),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((1100,250,1300,450),(0,0,0),(0,0,0)) \n",
    "    draw.polygon((900, 1070,1120, 1000,1150, 1100, 1100,1090,1050, 1200),(0,0,0),(0,0,0))\n",
    "    draw.pieslice((750, 1700, 950, 1900), 0,180,(0,0,0),(0,0,0))\n",
    "    draw.ellipse((900,550,1050,700),(0,0,0),(0,0,0))\n",
    "    draw.ellipse((650,100,850,300),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((1700,130,1900,330),(0,0,0),(0,0,0))\n",
    "    draw.polygon((150, 180, 200, 180, 250, 120, 230, 90, 130, 100),(0,0,0),(0,0,0))\n",
    "    return im\n",
    "# im_show=Draw_map2()\n",
    "# plt.imshow(im_show)\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlsAAAJCCAYAAAD3HAIiAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH1VJREFUeJzt3WusZXd93+Hvr55gIQINlBQ5tlNsySCZqnJiy0FKQFS5\nYFCKIZWoURVIg5ggXBTUVBGEqkF9lRuphCJMh8YCKmLjNCH4RWgDKAp9UQcMcvAFHMZglBlNbBWi\nOFEiB5tfX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zmMrl4/TprUxr01y2/meY1Pmx3neXxfy+2NVY+vSJH8x8/U5T+2zqerMUyMl\nyVunzQK3zqzm3Ib51Ek+WVWfq53TOCXnP1XUps+P027Kmb8kt3X5SPa/PFyaPZ46bAP8bM48xM4V\n0yaiP6mql0xj2zA/9vPzsQ3zI0lekuSR7v7yzNhWLB+73l8X8vtjVWNrq9WuUyMluSU7m1SvSXIq\nO6t+t8WPdPc1SV6R5OaqeunsjdNfFlt1/JKqelqSVyX53Wlom5ePM2zj8nAuVfXO7Bzr8MPT0Kkk\n3z/9PP2HJL9TVc9a1vQtkJ+Ps3tdzvyDbSuWj7O8v37byN8fqxpb5zrlz8ars5waqbsf6e4nu/tb\nSd6f72wK2vj51N0np38fTfLR7Lz2/Z4qatO8Isnnu/uRZLuXj4lTh+1SVT+T5CeT/NvpDSTT5pCv\nT9c/l519UF6QDZ8fB/j52Oj5kSRVdSTJTyX5yOmxbVg+zvb+mgX9/ljV2Ppskquq6orpr/ibsnMa\noI02bUN/yqmRTi8Ik9ckOf3JkrOeGmlR0ztaVT2jqp55+np2dvy9L/s8VdRip3ohzviLdFuXjxlO\nHTajqm5I8otJXtXdfzcz/r1VddF0/crszI+vbMH82NfPx6bPj8mPJflSd397c9imLx/nen/Non5/\nLPoTAXu9JHlldj4t8FCSdy57ehb0mn8kO6swv5DknunyyiT/I8m90/idSS6Zecw7p3n0YNbwEyIX\nmB9XZufTIH+W5P7Ty0GSf5LkU0m+nOSTSZ6zDfNjen3PSPL1JP94Zmxrlo/sROapJN/Mzr4SbzzI\n8pDkuuy86T6U5LcynU1j3S7nmB/Hs7OvyenfIe+b7vuvp5+je5J8Psm/2pL5se+fj02eH9P4B5K8\nedd9N3r5yLnfXxfy+8PpegAABlrVzYgAABtBbAEADCS2AAAGElsAAAOJLQCAgcQWAMBAYgsAYKD/\nD3dg4hVw4PmkAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x261d6c01d68>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def Draw_map3():\n",
    "    im = Image.new(\"RGB\", size=(2000,2000),color=(0,0,0)) \n",
    "    draw = ImageDraw.Draw(im,mode='RGB') \n",
    "    draw.rectangle((40,40,1960,1960),(255,255,255),(255,255,255))  \n",
    "    draw.polygon((1150, 1180, 1200, 1180, 1250, 1120, 1230, 1090, 1130, 1100),(0,0,0),(0,0,0))\n",
    "    draw.polygon((400,450,600,750,500,800),(0,0,0),(0,0,0))\n",
    "    draw.rectangle((1500,750,1700,950),(0,0,0),(0,0,0))\n",
    "    draw.rectangle((300,1500,1000,1750),(0,0,0),(0,0,0))\n",
    "    draw.ellipse((1450,1600,1600,1750),(0,0,0),(0,0,0))\n",
    "    draw.rectangle((1200,300,1400,500),(0,0,0),(0,0,0))\n",
    "    draw.ellipse((500,1000,700,1200),(0,0,0),(0,0,0))\n",
    "    draw.ellipse((750,900,700,1200),(0,0,0),(0,0,0))\n",
    "    return im\n",
    "im_show=Draw_map3()\n",
    "plt.imshow(im_show)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Function Scan is used to detect the distance between obstacles and robot.\n",
    "#Nearest(<50cm)||Near(50cm-130cm)||Medium(130cm-210cm)|Far(>210cm)\n",
    "#Furthest scanning distance is defined as 290cm\n",
    "def Scan(Current_x,Current_y,Angle,im):\n",
    "    Distance_level=0\n",
    "    Obstacle_distance=Robot_radium\n",
    "    Obstacle_distance_x=Current_x+Obstacle_distance*np.cos(Angle/180*np.pi)\n",
    "    Obstacle_distance_y=Current_y+Obstacle_distance*np.sin(Angle/180*np.pi)\n",
    "    while(im.getpixel((Obstacle_distance_x,Obstacle_distance_y))!=(0,0,0) and Obstacle_distance<250):#getpixiel obtains the degree of Gray Scale\n",
    "        Obstacle_distance+=5  #Search interval, can be changed\n",
    "        Obstacle_distance_x=Current_x+Obstacle_distance*np.cos(Angle/180*np.pi)\n",
    "        Obstacle_distance_y=Current_y+Obstacle_distance*np.sin(Angle/180*np.pi)\n",
    "    if 0<=Obstacle_distance<90:\n",
    "        Distance_level=0 #Nearear\n",
    "    elif 90<=Obstacle_distance<170:\n",
    "        Distance_level=1 #Near\n",
    "    elif 170<=Obstacle_distance<250:\n",
    "        Distance_level=2 #Medium\n",
    "    else:\n",
    "        Distance_level=3 #Far\n",
    "    return Distance_level"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Is_Crash(Current_x,Current_y,im):\n",
    "    Crash=False\n",
    "    Degree=[-150,-120,-90,-60,-30,0,30,60,90,120,150,180]\n",
    "    Distance=np.arange(0,50,5)\n",
    "    for i in Distance:\n",
    "        for j in Degree:\n",
    "            x=Current_x+i*np.cos(j/180*np.pi)\n",
    "            y=Current_y+i*np.sin(j/180*np.pi)\n",
    "            if im.getpixel((x,y))==(0,0,0):\n",
    "                Crash=True\n",
    "                break\n",
    "        if Crash==True:\n",
    "                break\n",
    "    return Crash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Random_start(im):\n",
    "    Angle=np.random.random()*360\n",
    "    x,y=np.random.random(2)*2000\n",
    "    while(Is_Crash(x,y,im)==True):\n",
    "        x,y=np.random.random(2)*2000\n",
    "    return x,y,Angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Direction_min_level(Degree,Current_x,Current_y,Current_angle,im):\n",
    "    Level=[]\n",
    "    Degree=Degree+Current_angle\n",
    "    for i in Degree:\n",
    "        Level.append(Scan(Current_x,Current_y,i,im))\n",
    "    return min(Level)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Output_state_index(Left_min,Right_min,Up_min):\n",
    "    LRU=[]\n",
    "    LRU.append(Left_min)\n",
    "    LRU.append(Right_min)\n",
    "    LRU.append(Up_min)\n",
    "    return LRU[0]*16+LRU[1]*4+LRU[2]\n",
    "# print(Output_state_index(Left_min,Right_min,Up_min))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Choose_action is used to selection an action during the training process. It is based on the greedy strategy, if the random \n",
    "#chosen float(0-1) is inferior to current epsilon, robot choose random action to explore, if not, choose maximun Q value\n",
    "#action based on Q Table, more precisely based on the action-state range\n",
    "def Choose_action(Q_Table,Current_state,Action_times):\n",
    "    Epsilon=Epsilon_final+(Epsilon_start-Epsilon_final)*np.exp(-1*Decay_rate*Action_times)\n",
    "    State_action=Q_Table[Current_state,:]\n",
    "    if(np.random.random()<Epsilon or np.all(State_action==[0])):\n",
    "        Next_action=np.random.randint(Q_table1_actions_length)\n",
    "    else:\n",
    "        Next_action=np.argmax(State_action)\n",
    "    return Next_action"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Output_next_state(Current_x,Current_y,Current_angle,Action,im):\n",
    "    Reward=1\n",
    "    Crash=False\n",
    "    if Action==0:\n",
    "        Next_x=Current_x+Velocity_tripod*np.cos(Current_angle/180*np.pi)\n",
    "        Next_y=Current_y+Velocity_tripod*np.sin(Current_angle/180*np.pi)\n",
    "        Next_angle=Current_angle\n",
    "        if Is_Crash(Next_x,Next_y,im)==True:\n",
    "            Crash=True\n",
    "            Reward=-500\n",
    "        else:\n",
    "            Reward=2\n",
    "    elif Action==1:\n",
    "        Next_x=Current_x-Velocity_tripod*np.cos(Current_angle/180*np.pi)\n",
    "        Next_y=Current_y-Velocity_tripod*np.sin(Current_angle/180*np.pi)\n",
    "        Next_angle=Current_angle\n",
    "        if Is_Crash(Next_x,Next_y,im)==True:\n",
    "            Crash=True\n",
    "            Reward=-500\n",
    "    elif Action==2:\n",
    "        Next_x=Current_x\n",
    "        Next_y=Current_y\n",
    "        Next_angle=Current_angle-45\n",
    "    elif Action==3:\n",
    "        Next_x=Current_x\n",
    "        Next_y=Current_y\n",
    "        Next_angle=Current_angle+45        \n",
    "    return Next_x,Next_y,Next_angle,Reward,Crash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Movement_plot(Vec_x,Vec_y):\n",
    "    im=Image.new(\"RGB\", size=(2000,2000),color=(0,0,0))\n",
    "    draw = ImageDraw.Draw(im,mode='RGB')\n",
    "    draw.rectangle((40,40,1960,1960),(255,255,255),(255,255,255))\n",
    "    draw.rectangle((1500,1000,1650,1150),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((400,700,550,850),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((200,300,350,450),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((1500,500,1550,650),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((1200,1400,1350,1550),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((700,1200,850,1350),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((300,1600,450,1750),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((100,1100,250,1250),(0,0,0),(0,0,0)) \n",
    "    draw.ellipse((1100,250,1250,400),(0,0,0),(0,0,0)) \n",
    "    draw.polygon((900, 1070,1120, 1000,1150, 1100, 1100,1090,1050, 1200),(0,0,0),(0,0,0))\n",
    "    draw.pieslice((750, 1700, 900, 1850), 0,180,(0,0,0),(0,0,0))\n",
    "    draw.ellipse((900,550,1050,700),(0,0,0),(0,0,0))\n",
    "    draw.ellipse((650,100,750,200),(0,0,0),(0,0,0)) \n",
    "    draw.rectangle((1700,130,1800,230),(0,0,0),(0,0,0))\n",
    "    draw.polygon((150, 180, 200, 180, 250, 120, 230, 90, 130, 100),(0,0,0),(0,0,0))\n",
    "    draw.ellipse((Vec_x[0]-40,Vec_y[0]-40, Vec_x[0]+40,Vec_y[0]+40),(0,255,0),(0,255,0)) \n",
    "    for i,j in zip(Vec_x[1:],Vec_y[1:]):\n",
    "        draw.ellipse((i-40,j-40, i+40,j+40),(0,255,0),(0,255,0)) \n",
    "    return im"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [],
   "source": [
    "Q_table1_gait=np.loadtxt(r\"E:\\Graduate\\python\\Q_Table_notgait_finish\\Q_Table1_notgait\\Q_Table1_notgait_1.txt\")\n",
    "Q_table1_gait=pd.DataFrame(Q_table1_gait,columns=Q_table1_actions,index=Q_table1_states)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "******************\n",
      "0\n",
      "******************\n",
      "******************\n",
      "20\n",
      "******************\n",
      "******************\n",
      "40\n",
      "******************\n",
      "******************\n",
      "60\n",
      "******************\n",
      "******************\n",
      "80\n",
      "******************\n",
      "******************\n",
      "100\n",
      "******************\n",
      "******************\n",
      "120\n",
      "******************\n",
      "******************\n",
      "140\n",
      "******************\n",
      "******************\n",
      "160\n",
      "******************\n",
      "******************\n",
      "180\n",
      "******************\n",
      "******************\n",
      "200\n",
      "******************\n",
      "******************\n",
      "220\n",
      "******************\n",
      "******************\n",
      "240\n",
      "******************\n",
      "******************\n",
      "260\n",
      "******************\n",
      "******************\n",
      "280\n",
      "******************\n",
      "******************\n",
      "300\n",
      "******************\n",
      "******************\n",
      "320\n",
      "******************\n",
      "******************\n",
      "340\n",
      "******************\n",
      "******************\n",
      "360\n",
      "******************\n",
      "******************\n",
      "380\n",
      "******************\n",
      "******************\n",
      "400\n",
      "******************\n",
      "******************\n",
      "420\n",
      "******************\n",
      "******************\n",
      "440\n",
      "******************\n",
      "******************\n",
      "460\n",
      "******************\n",
      "******************\n",
      "480\n",
      "******************\n",
      "******************\n",
      "500\n",
      "******************\n",
      "******************\n",
      "520\n",
      "******************\n",
      "******************\n",
      "540\n",
      "******************\n",
      "******************\n",
      "560\n",
      "******************\n",
      "******************\n",
      "580\n",
      "******************\n",
      "******************\n",
      "600\n",
      "******************\n",
      "******************\n",
      "620\n",
      "******************\n",
      "******************\n",
      "640\n",
      "******************\n",
      "******************\n",
      "660\n",
      "******************\n",
      "******************\n",
      "680\n",
      "******************\n",
      "******************\n",
      "700\n",
      "******************\n",
      "******************\n",
      "720\n",
      "******************\n",
      "******************\n",
      "740\n",
      "******************\n",
      "******************\n",
      "760\n",
      "******************\n",
      "******************\n",
      "780\n",
      "******************\n",
      "******************\n",
      "800\n",
      "******************\n",
      "******************\n",
      "820\n",
      "******************\n",
      "******************\n",
      "840\n",
      "******************\n",
      "******************\n",
      "860\n",
      "******************\n",
      "******************\n",
      "880\n",
      "******************\n",
      "******************\n",
      "900\n",
      "******************\n",
      "******************\n",
      "920\n",
      "******************\n",
      "******************\n",
      "940\n",
      "******************\n",
      "******************\n",
      "960\n",
      "******************\n",
      "******************\n",
      "980\n",
      "******************\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlsAAAJCCAYAAAD3HAIiAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3W2sZVd93/Hfn5lgIQINlNRyxk6xpQHJVJUTWw5SAqLK\nAwal2KQSHVQF0iAmCBcFtVVkh6pBfZUnUglFGA2NBVTExnkg+EVoA1YU+qLGGDTxEziMwYgZTWwV\npDhRIgebf1+cfTz73jn3nrPP2Wut/1rr+7m6mjP7noe199p7rd9Z+8ncXQAAAEjjeaULAAAA0DLC\nFgAAQEKELQAAgIQIWwAAAAkRtgAAABIibAEAACSUPWyZ2Q1m9qiZnTGzW3J/PgAAQE6W8zpbZnZE\n0l9J+mlJZyV9UdJb3f2RbIUAAADIKPfI1vWSzrj71939HyXdKenGzGUAAADI5mjmzzsm6Vuj/5+V\n9GP7n2RmJyWdHP57bYZyAQAAPMfdba73yh22NuLupySdkiQz435CAACgWrl3I56TdMXo/5cP0wAA\nAJqUO2x9UdJxM7vSzJ4v6YSkuzOXAQAA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bpNi12q10g6r8XQby9+\nwt2vkfQGSTeb2WvHfxy+WXR1/RIze76kN0n6g2FSz+vHHj2uDwcxs/dpca3DTwyTzkv64WF7+o+S\nft/MXlyqfBmxfaz2Vu39wtbF+rGif31OyvYjatg66JY/zbMVt0Zy9yfc/Vl3/56kj+jCrqDml5O7\nnxv+fVLSp7SY96m3imrNGyR92d2fkPpePwbcOmwfM/sFST8r6d8NHYiG3SHfHh5/SYtjUF6hxpfH\nFttH08tDkszsqKSfk/TJ5bQe1o9V/asytR9Rw9YXJR03syuHb/EntLgNUNOGfegX3RppuSIM3ixp\neWbJylsj5Spvamb2QjN70fKxFgf+PqSJt4rKW+os9nwj7XX9GOHWYSNmdoOkX5H0Jnf/+9H0HzSz\nI8Pjq7RYHl/vYHlM2j5aXx6Dn5L0VXd/bndY6+vHQf2rcrUfuc8I2PRX0hu1OFvgMUnvK12eTPP8\nE1oMYT4g6fTw+0ZJ/1PSg8P0uyVdNnrN+4Zl9KgqPENkzfK4SouzQf5S0sPL9UDSP5V0j6SvSfqc\npJf2sDyG+XuhpG9L+iejad2sH1qEzPOSvqvFsRLv2GZ9kHSdFp3uY5J+V8PdNGr7PWB5nNHiWJNl\nG/Lh4bn/ZtiOTkv6sqR/3cnymLx9tLw8hukflfSufc9tev3Qwf1rlvaD2/UAAAAkFHU3IgAAQBMI\nWwAAAAkRtgAAABIibAEAACRE2AIAAEiIsAUAAJAQYQsAACCh/w9nrHkJLbIXFAAAAABJRU5ErkJg\ngg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x261d90e9f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def test(Q_Table):\n",
    "    Crash=False\n",
    "    im=Draw_map1()\n",
    "    Current_x,Current_y,Current_angle=Random_start(im)\n",
    "    Test_time=0\n",
    "    Vec_x=[]\n",
    "    Vec_y=[]\n",
    "    while Test_time<1000:\n",
    "        Current_left_obstacle_level=Direction_min_level(Left_degree,Current_x,Current_y,Current_angle,im)\n",
    "        Current_right_obstacle_level=Direction_min_level(Right_degree,Current_x,Current_y,Current_angle,im)\n",
    "        Current_up_obstacle_level=Direction_min_level(Up_degree,Current_x,Current_y,Current_angle,im)\n",
    "        Current_state=Output_state_index(Current_left_obstacle_level,Current_right_obstacle_level,Current_up_obstacle_level)\n",
    "        Next_action=np.argmax(Q_Table[Current_state])\n",
    "#         print(\"------------------------------------------------------------------------------------------\")\n",
    "#         print('Current_x=%f   Current_y=%f   Current_angle=%f'%(Current_x,Current_y,(Current_angle%360)))\n",
    "        Next_x,Next_y,Next_angle,Reward,Crash=Output_next_state(Current_x,Current_y,Current_angle,Next_action,im)\n",
    "#         print('Current_state=%d'%Current_state)\n",
    "#         print('Next_action=%d'%Next_action)\n",
    "#         print('Next_x=%f   Next_y=%f   Next_angle=%f'%(Next_x,Next_y,(Next_angle%360)))\n",
    "        \n",
    "        Vec_x.append(Current_x)\n",
    "        Vec_y.append(Current_y)\n",
    "        if Crash==True:\n",
    "            print('Boom')\n",
    "            print(Test_time)\n",
    "            break\n",
    "        else:\n",
    "            if(Test_time%20==0):\n",
    "                print(\"******************\")\n",
    "                print(Test_time)\n",
    "                im_show=Movement_plot(Vec_x,Vec_y)\n",
    "                print(\"******************\")\n",
    "                plt.imshow(im_show)\n",
    "                plt.savefig((r\"E:\\Graduate\\python\\Q_Table_notgait_finish\\Q_Table1_notgait\\Pic\\picture\")+str(Test_time)+\".png\")\n",
    "#                 plt.show()\n",
    "        Current_x=Next_x\n",
    "        Current_y=Next_y\n",
    "        Current_angle=Next_angle\n",
    "        Test_time+=1\n",
    "test(Q_table1_gait.as_matrix())\n",
    "# np.savetxt(\"Q_Table_try.txt\",Q_Table_Final.as_matrix())\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Q_Table_Final' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-130-dedcef448dba>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mQ_Table_Final\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m30\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'Q_Table_Final' is not defined"
     ]
    }
   ],
   "source": [
    "Q_Table_Final.iloc[30,:]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
